package com.aigou.admin.aigouspringboot.controller.user;

import com.aigou.admin.aigouspringboot.common.LogScope;
import com.aigou.admin.aigouspringboot.entity.Product;
import com.aigou.admin.aigouspringboot.entity.ReceivingAddress;
import com.aigou.admin.aigouspringboot.entity.dto.ShopCartProductDTO;
import com.aigou.admin.aigouspringboot.result.Result;
import com.aigou.admin.aigouspringboot.service.ShopCartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("/userShopCartController")
@RequestMapping("/user/shopCart")
public class ShopCartController {

    @Resource
    private ShopCartService shopCartService;



    @GetMapping("/address/{userId}")
    @LogScope(title = "购物车管理模块", content = "根据useId查询地址信息")
    public Result getAddress(@PathVariable String userId){
        List<ReceivingAddress> address = shopCartService.getAddress(userId);
        return Result.success(address);
    }

    @GetMapping("/product/{userId}")
    @LogScope(title = "购物车管理模块", content = "根据useId查询商品信息")
    public Result getProduct(@PathVariable String userId){
        List<Product> products = shopCartService.getProduct(userId);
        return Result.success(products);
    }

    @PostMapping("/addProduct")
    @LogScope(title = "购物车管理模块", content = "添加信息")
    public Result addProductToCart(@RequestBody ShopCartProductDTO shopCartProductDTO) {
        int i = shopCartService.addProductToCart(shopCartProductDTO);
        return i>0 ? Result.success() : Result.error();
    }


}
